package com.example.administrator.pomelostreet.tata;

import com.example.administrator.pomelostreet.tatajavabean.recommend_forums;
import com.example.administrator.pomelostreet.tatajavabean.topics;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：韩飞  日期：2017/2/9.
 */

public class ParseJson {



    private static List<recommend_forums> list;
    private static List<topics> list1;



    public static List<recommend_forums> parseJson(String json) throws JSONException {
    //
        list = new ArrayList<>();

    JSONObject jsonObject= new JSONObject(json);
    JSONArray jsonArray= jsonObject.getJSONArray("recommend_forums");
    for(int i = 0;i<jsonArray.length();i++){
        JSONObject jsonObject1=jsonArray.getJSONObject(i);
        recommend_forums recommend =new recommend_forums();
        recommend.setId(jsonObject1.getInt("id"));
        recommend.setName(jsonObject1.getString("name"));
        recommend.setIcon(jsonObject1.getString("icon"));
        recommend.setIcon2(jsonObject1.getString("icon2"));
        recommend.setIcon3(jsonObject1.getString("icon3"));
        list.add(recommend);
    }

    return list;
}

    public static  List<topics> parseJson2(String json) throws JSONException {
        list1 = new ArrayList<>();
        JSONObject jsonObject1 = new JSONObject(json);
        JSONArray jsonArray1 = jsonObject1.getJSONArray("topics");
        for(int i = 0;i<jsonArray1.length();i++){
            JSONObject jsonObject2 =jsonArray1.getJSONObject(i);
            topics top =new topics();
            top.setId(jsonObject2.getInt("id"));
            top.setContent(jsonObject2.getString("content"));
            top.setImages(jsonObject2.getString("images"));
            top.setTitle(jsonObject2.getString("title"));

            list1.add(top);
        }


        return list1;
    }


}
